package com.novak.rss.reader;

import java.util.ArrayList;
import java.util.List;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

public class FeedRecommendViewActivity extends ListActivity
{
  private List<Feed> defaultFeeds = new ArrayList<Feed>();

  public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.frv);
    String[] feedNames = getResources().getStringArray(
        R.array.feed_names);
    String[] feedUrls = getResources()
        .getStringArray(R.array.feed_urls);
    for (int i = 0; i < feedNames.length; i++)
    {
      defaultFeeds.add(new Feed(feedNames[i], feedUrls[i]));
    }
    setListAdapter(new FeedsListAdapter(this, defaultFeeds));
    
  }

 

  protected void onListItemClick(ListView l, View v, int position,
      long id)
  {

    Feed f = (Feed) defaultFeeds.get(position);
    Bundle b = new Bundle();
    b.putString("path", f.getUrl());
    b.putString("title", f.getName());
    Intent intent = new Intent();
    intent.setClass(this, RSSProcessActivity.class);
    intent.putExtras(b);
    this.startActivityForResult(intent, 0);
  }

  protected void onActivityResult(int requestCode, int resultCode,
      Intent data)
  {
    switch (resultCode)
    {
      case -1:
        Bundle bunde = data.getExtras();
        String error = bunde.getString("error");
        showError(error);
        break;
      default:
        break;
    }
  }

  private void showError(String mess)
  {
    new AlertDialog.Builder(this).setTitle("Message").setMessage(mess)
        .setNegativeButton(getResources().getString(R.string.ok),
            new DialogInterface.OnClickListener()
            {
              public void onClick(DialogInterface dialog, int which)
              {
              }
            }).show();
  }

}
